﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class ClsBaoGia
    {
        private string mChucVuNhanVien = "";
        private string mDiaChiGiaoHang = "";
        private string mDienGiai = "";
        private string mDienThoai = "";
        private string mDienThoaiNhanVien = "";
        private string mEmail = "";
        private string mEmailNhanVien = "";
        private string mFax = "";
        private string mFaxNhanVien = "";
        private string mHieuLucDenNgay = "";
        private string mKhoa = "";
        private string mKhoaDonDatHang = "";
        private string mKhoaHoaDon = "";
        private string mKhoaHopDong = "";
        private string mKhoaKhachHang = "";
        private string mKhoaLoaiGia = "";
        private string mKhoaNhanVien = "";
        private string mKhoaNhanVienSua = "";
        private string mKhoaNhanVienTao = "";
        private string mKhoaYeuCauBaoGia = "";
        private string mLoaiTien = "";
        private string mNgayChungTu = "";
        private string mNgaySua = "";
        private string mNgayTao = "";
        private string mNguoiLienHe = "";
        private string mReply = "";
        private string mSoChungTu = "";
        private string mSoYeuCauBaoGia = "";
        private double mTienHang = 0.0;
        private double mTienHangNT = 0.0;
        private double mTienThue = 0.0;
        private double mTienThueNT = 0.0;
        private int mTinhTrang = 0;
        private double mTyGia = 0.0;

        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM BH_BaoGiaChiTietTmp WHERE KhoaBaoGia = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
            commandText = "DELETE FROM BH_BaoGiaChiTietDieuKhoanTmp WHERE KhoaBaoGia = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool ConfirmStatus(string strKhoa, int intStatus)
        {
            bool flag=false;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "UPDATE BH_BaoGia SET TinhTrang = " + Conversions.ToString(intStatus) + " WHERE RTRIM(Khoa) = '" + strKhoa.Trim() + "'";
                bool flag2 = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }) > 0;
                flag = flag2;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag = true;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DelData(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, pKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_sp_BaoGiaDel", commandParameters);
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DeleteBaoGiaTemp(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "DELETE FROM BH_DieuKhoanBaoGiaTemplate WHERE Khoa = '" + pKhoa.Trim() + "'";
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetDataPrint(string strKhoa, string strLanguage = "VIET")
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, strLanguage);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_BC_BaoGia", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintDK(string strKhoa, string strLanguage = "VIET")
        {
            DataTable table;
            try
            {
                string commandText = " SELECT DK.NoiDung" + strLanguage + " As NoiDung, IsNull(DKBG.Ten" + strLanguage + ",'') as DKBaoGia, DK.HienThi  FROM BH_BaoGia BG  LEFT JOIN BH_BaoGiaChiTietDieuKhoan DK on BG.Khoa = DK.KhoaBaoGia  LEFT JOIN DM_DieuKhoanBaoGia DKBG on DK.KhoaDieuKhoan = DKBG.Khoa  WHERE BG.Khoa = '" + strKhoa + "' And Rtrim(DK.NoiDung" + strLanguage + ") <> '' order by DK.Khoa ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDetails(string pKhoa)
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "  SELECT BGCT.Khoa,BGCT.KhoaBaoGia,BGCT.Loai as Loai, DC.Ten" + modGeneral.H_LANGUAGE + " as TenLoai, BGCT.KhoaHangHoa, HH.Ma as MaHang,  HH.Ten" + modGeneral.H_LANGUAGE + " as TenHang,  QG.Khoa as KhoaQG, QG.Ten" + modGeneral.H_LANGUAGE + " as XuatXu,  BGCT.KhoaDonViTinh as KhoaDVT, DVT.Ten" + modGeneral.H_LANGUAGE + " as DVT,  BGCT.QuyCach,BGCT.SoLuong,BGCT.DonGia,   BGCT.TienHang,BGCT.TyLeThue as ThueSuat, BGCT.TienThue, BGCT.KhoaThietBi,  BGCT.KhoaQuocGia, BGCT.KhoaHangSanXuat, HSX.Ten" + modGeneral.H_LANGUAGE + " as HangSanXuat, BGCT.ThoiGianBaoHanh,  BGCT.KhoaCha, BGCT.DienGiai As DienGiaiChiTiet  FROM BH_BaoGiaChiTiet  BGCT  LEFT JOIN BH_BaoGia BG on  BGCT.KhoaBaoGia = BG.Khoa  LEFT JOIN DM_HangHoa HH on BGCT.KhoaHangHoa =HH.Khoa\t LEFT JOIN HT_DungChung DC on BGCT.Loai = DC.Ma and DC.Loai = '0000000004'  LEFT JOIN DM_QuocGia QG on BGCT.KhoaQuocGia = QG.Khoa  LEFT JOIN DM_HangSanXuat HSX on BGCT.KhoaHangSanXuat = HSX.Khoa  LEFT JOIN DM_DonViTinh DVT on BGCT.KhoaDonViTinh =DVT.Khoa WHERE BGCT.KhoaBaoGia = '" + pKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDetailsIntoHoaDon(string pKhoa)
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "  SELECT BGCT.KhoaHangHoa, HH.Ma as MaHang,  HH.Ten" + modGeneral.H_LANGUAGE + " as TenHang,   BGCT.KhoaDonViTinh as KhoaDVT, DVT.Ten" + modGeneral.H_LANGUAGE + " as DVT,  BGCT.QuyCach,BGCT.SoLuong,BGCT.DonGia,   BGCT.TienHang,BGCT.TyLeThue as ThueSuat, BGCT.TienThue,  HH.KhoaTKHangHoa, TKH.SoTaiKhoan as TaiKhoanHangHoa, HH.KhoaTKGiaVon, TKV.SoTaiKhoan as TaiKhoanGiaVon  FROM BH_BaoGiaChiTiet BGCT  LEFT JOIN DM_HangHoa HH on BGCT.KhoaHangHoa =HH.Khoa\t LEFT JOIN DM_DonViTinh DVT on BGCT.KhoaDonViTinh =DVT.Khoa  LEFT JOIN DM_TaiKhoan TKH on HH.KhoaTKHangHoa =TKH.Khoa  LEFT JOIN DM_TaiKhoan TKV on HH.KhoaTKGiaVon =TKV.Khoa  WHERE BGCT.KhoaBaoGia = '" + pKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDieuKhoan(string pKhoa)
        {
            string commandText = "SELECT CT.Khoa, CT.KhoaDieuKhoan, DK.Ten" + modGeneral.H_LANGUAGE + " as DieuKhoan, CT.NoiDungViet, CT.NoiDungAnh, CT.HienThi  FROM BH_BaoGiaChiTietDieuKhoan CT left join DM_DieuKhoanBaoGia DK on CT.KhoaDieuKhoan = DK.Khoa  WHERE CT.KhoaBaoGia = '" + pKhoa + "' ORDER BY CT.Khoa";
            return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
        }

        public DataTable GetDieuKhoanTemplate(string strLoai)
        {
            string commandText = "SELECT T.Khoa, T.KhoaDieuKhoan, DK.Ten" + modGeneral.H_LANGUAGE + " as DieuKhoan, T.NoiDungViet, T.NoiDungAnh, T.HienThi  FROM BH_DieuKhoanBaoGiaTemplate T left join DM_DieuKhoanBaoGia DK on T.KhoaDieuKhoan = DK.Khoa  WHERE T.LoaiChungTu = '" + strLoai + "' ORDER BY STT ";
            return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
        }

        public DataTable GetList(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT BG.Khoa, BG.SoChungTu, dbo.Char2Date(BG.NgayChungTu) as Ngay, DT.Ten" + modGeneral.H_LANGUAGE + " as KhachHang,  DTT.Ten" + modGeneral.H_LANGUAGE + " as NhanVien,  BG.DienGiai FROM BH_BaoGia BG LEFT JOIN DM_DoiTuong DT ON BG.KhoaKhachHang = DT.Khoa  LEFT JOIN DM_DoiTuong DTT ON BG.KhoaNhanVien = DTT.Khoa " + str2 + " ORDER BY BG.NgayChungTu, BG.SoChungTu";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool IsDuplicateVoucherNo(string strVoucherNo, string strKeyTable)
        {
            string commandText = "SELECT * FROM BH_BaoGia Where Rtrim(SoChungTu) = '" + strVoucherNo.Trim() + "' AND Khoa <> '" + strKeyTable + "'";
            return (DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0].Rows.Count > 0);
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM BH_BaoGia WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKhachHang = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDienThoai = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mFax = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mEmail = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mNguoiLienHe = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaLoaiGia = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mDiaChiGiaoHang = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaNhanVien = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mHieuLucDenNgay = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mTinhTrang = Conversions.ToInteger(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetInt32));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienTao = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                    this.mNgayTao = Conversions.ToString(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienSua = Conversions.ToString(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetString));
                    this.mNgaySua = Conversions.ToString(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetString));
                    this.mTienHangNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienHang = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThueNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThue = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetDecimal));
                    this.mChucVuNhanVien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetString));
                    this.mDienThoaiNhanVien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetString));
                    this.mFaxNhanVien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1a, modGeneral.typeOfColumn.GetString));
                    this.mEmailNhanVien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1b, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1c, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonDatHang = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1d, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 30, modGeneral.typeOfColumn.GetString));
                    this.mKhoaYeuCauBaoGia = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1f, modGeneral.typeOfColumn.GetString));
                    this.mSoYeuCauBaoGia = Conversions.ToString(modGeneral.GetValue(dataReader, 0x20, modGeneral.typeOfColumn.GetString));
                    this.mReply = Conversions.ToString(modGeneral.GetValue(dataReader, 0x21, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x23];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, this.mSoChungTu);
                commandParameters[2] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, this.mNgayChungTu);
                commandParameters[3] = DBHelper.createParameter("@KhoaKhachHang", DbType.Int64, ParameterDirection.Input, this.mKhoaKhachHang);
                commandParameters[4] = DBHelper.createParameter("@DienThoai", DbType.Int64, ParameterDirection.Input, this.mDienThoai);
                commandParameters[5] = DBHelper.createParameter("@Fax", DbType.Int64, ParameterDirection.Input, this.mFax);
                commandParameters[6] = DBHelper.createParameter("@Email", DbType.Int64, ParameterDirection.Input, this.mEmail);
                commandParameters[7] = DBHelper.createParameter("@NguoiLienHe", DbType.Int64, ParameterDirection.Input, this.mNguoiLienHe);
                commandParameters[8] = DBHelper.createParameter("@KhoaLoaiGia", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiGia);
                commandParameters[9] = DBHelper.createParameter("@DiaChiGiaoHang", DbType.Int64, ParameterDirection.Input, this.mDiaChiGiaoHang);
                commandParameters[10] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[11] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[12] = DBHelper.createParameter("@KhoaNhanVien", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVien);
                commandParameters[13] = DBHelper.createParameter("@HieuLucDenNgay", DbType.Int64, ParameterDirection.Input, this.mHieuLucDenNgay);
                commandParameters[14] = DBHelper.createParameter("@TinhTrang", DbType.Double, ParameterDirection.Input, this.mTinhTrang);
                commandParameters[15] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[0x10] = DBHelper.createParameter("@KhoaNhanVienTao", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienTao);
                commandParameters[0x11] = DBHelper.createParameter("@NgayTao", DbType.Int64, ParameterDirection.Input, this.mNgayTao);
                commandParameters[0x12] = DBHelper.createParameter("@KhoaNhanVienSua", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienSua);
                commandParameters[0x13] = DBHelper.createParameter("@NgaySua", DbType.Int64, ParameterDirection.Input, this.mNgaySua);
                commandParameters[20] = DBHelper.createParameter("@TienHangNT", DbType.Date, ParameterDirection.Input, this.mTienHangNT);
                commandParameters[0x15] = DBHelper.createParameter("@TienHang", DbType.Date, ParameterDirection.Input, this.mTienHang);
                commandParameters[0x16] = DBHelper.createParameter("@TienThueNT", DbType.Date, ParameterDirection.Input, this.mTienThueNT);
                commandParameters[0x17] = DBHelper.createParameter("@TienThue", DbType.Date, ParameterDirection.Input, this.mTienThue);
                commandParameters[0x18] = DBHelper.createParameter("@ChucVuNhanVien", DbType.Int64, ParameterDirection.Input, this.mChucVuNhanVien);
                commandParameters[0x19] = DBHelper.createParameter("@DienThoaiNhanVien", DbType.Int64, ParameterDirection.Input, this.mDienThoaiNhanVien);
                commandParameters[0x1a] = DBHelper.createParameter("@FaxNhanVien", DbType.Int64, ParameterDirection.Input, this.mFaxNhanVien);
                commandParameters[0x1b] = DBHelper.createParameter("@EmailNhanVien", DbType.Int64, ParameterDirection.Input, this.mEmailNhanVien);
                commandParameters[0x1c] = DBHelper.createParameter("@KhoaHopDong", DbType.Int64, ParameterDirection.Input, this.mKhoaHopDong);
                commandParameters[0x1d] = DBHelper.createParameter("@KhoaDonDatHang", DbType.Int64, ParameterDirection.Input, this.mKhoaDonDatHang);
                commandParameters[30] = DBHelper.createParameter("@KhoaHoaDon", DbType.Int64, ParameterDirection.Input, this.mKhoaHoaDon);
                commandParameters[0x1f] = DBHelper.createParameter("@KhoaYeuCauBaoGia", DbType.Int64, ParameterDirection.Input, this.mKhoaYeuCauBaoGia);
                commandParameters[0x20] = DBHelper.createParameter("@SoYeuCauBaoGia", DbType.Int64, ParameterDirection.Input, this.mSoYeuCauBaoGia);
                commandParameters[0x21] = DBHelper.createParameter("@Reply", DbType.Int64, ParameterDirection.Input, this.mReply);
                commandParameters[0x22] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_sp_BaoGia", commandParameters);
                flag = Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[0x22].Value, 0, false);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public void SetBlank()
        {
            this.mKhoa = "";
            this.mSoChungTu = "";
            this.mNgayChungTu = "";
            this.mKhoaKhachHang = "";
            this.mDienThoai = "";
            this.mFax = "";
            this.mEmail = "";
            this.mNguoiLienHe = "";
            this.mKhoaLoaiGia = "";
            this.mDiaChiGiaoHang = "";
            this.mLoaiTien = "";
            this.mTyGia = 0.0;
            this.mKhoaNhanVien = "";
            this.mHieuLucDenNgay = "";
            this.mTinhTrang = 0;
            this.mDienGiai = "";
            this.mKhoaNhanVienTao = "";
            this.mNgayTao = "";
            this.mKhoaNhanVienSua = "";
            this.mNgaySua = "";
            this.mTienHangNT = 0.0;
            this.mTienHang = 0.0;
            this.mTienThueNT = 0.0;
            this.mTienThue = 0.0;
            this.mChucVuNhanVien = "";
            this.mDienThoaiNhanVien = "";
            this.mFaxNhanVien = "";
            this.mEmailNhanVien = "";
            this.mKhoaHopDong = "";
            this.mKhoaDonDatHang = "";
            this.mKhoaHoaDon = "";
        }

        public DataTable ShowList(string strKeyFilter = "", string strFiledNameFilter = "")
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            string str3 = "";
            string str = "";
            try
            {
                if (strKeyFilter.Trim() != "")
                {
                    object instance = Strings.Split(strKeyFilter, "|", -1, CompareMethod.Binary);
                    int num2 = Information.UBound((Array) instance, 1);
                    for (int i = 0; i <= num2; i++)
                    {
                        if (str.Trim() == "")
                        {
                            str = Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject("'", NewLateBinding.LateIndexGet(instance, new object[] { i }, null)), "'"));
                        }
                        else
                        {
                            str = Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(str + ",'", NewLateBinding.LateIndexGet(instance, new object[] { i }, null)), "'"));
                        }
                    }
                    str3 = " AND " + strFiledNameFilter + " IN (" + str + ")";
                }
                commandText = " SELECT Khoa, Rtrim(Ma) as Ma, Rtrim(Ten" + modGeneral.H_LANGUAGE + ") as Ten  FROM BH_BaoGia WHERE Active = 1 " + str3 + " ORDER BY Ten" + modGeneral.H_LANGUAGE;
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool TrungMa(string pMa, string pKhoa)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM BH_BaoGia WHERE RTRIM(Ma) = '" + pMa.Trim() + "' AND RTRIM(Khoa) <> '" + pKhoa.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public bool WasUsed(string pKhoa)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM BH_BaoGia WHERE RTRIM(Khoa) = '" + pKhoa.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public string ChucVuNhanVien
        {
            get
            {
                return this.mChucVuNhanVien;
            }
            set
            {
                this.mChucVuNhanVien = value;
            }
        }

        public string DiaChiGiaoHang
        {
            get
            {
                return this.mDiaChiGiaoHang;
            }
            set
            {
                this.mDiaChiGiaoHang = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DienThoai
        {
            get
            {
                return this.mDienThoai;
            }
            set
            {
                this.mDienThoai = value;
            }
        }

        public string DienThoaiNhanVien
        {
            get
            {
                return this.mDienThoaiNhanVien;
            }
            set
            {
                this.mDienThoaiNhanVien = value;
            }
        }

        public string Email
        {
            get
            {
                return this.mEmail;
            }
            set
            {
                this.mEmail = value;
            }
        }

        public string EmailNhanVien
        {
            get
            {
                return this.mEmailNhanVien;
            }
            set
            {
                this.mEmailNhanVien = value;
            }
        }

        public string Fax
        {
            get
            {
                return this.mFax;
            }
            set
            {
                this.mFax = value;
            }
        }

        public string FaxNhanVien
        {
            get
            {
                return this.mFaxNhanVien;
            }
            set
            {
                this.mFaxNhanVien = value;
            }
        }

        public string HieuLucDenNgay
        {
            get
            {
                return this.mHieuLucDenNgay;
            }
            set
            {
                this.mHieuLucDenNgay = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaDonDatHang
        {
            get
            {
                return this.mKhoaDonDatHang;
            }
            set
            {
                this.mKhoaDonDatHang = value;
            }
        }

        public string KhoaHoaDon
        {
            get
            {
                return this.mKhoaHoaDon;
            }
            set
            {
                this.mKhoaHoaDon = value;
            }
        }

        public string KhoaHopDong
        {
            get
            {
                return this.mKhoaHopDong;
            }
            set
            {
                this.mKhoaHopDong = value;
            }
        }

        public string KhoaKhachHang
        {
            get
            {
                return this.mKhoaKhachHang;
            }
            set
            {
                this.mKhoaKhachHang = value;
            }
        }

        public string KhoaLoaiGia
        {
            get
            {
                return this.mKhoaLoaiGia;
            }
            set
            {
                this.mKhoaLoaiGia = value;
            }
        }

        public string KhoaNhanVien
        {
            get
            {
                return this.mKhoaNhanVien;
            }
            set
            {
                this.mKhoaNhanVien = value;
            }
        }

        public string KhoaNhanVienSua
        {
            get
            {
                return this.mKhoaNhanVienSua;
            }
            set
            {
                this.mKhoaNhanVienSua = value;
            }
        }

        public string KhoaNhanVienTao
        {
            get
            {
                return this.mKhoaNhanVienTao;
            }
            set
            {
                this.mKhoaNhanVienTao = value;
            }
        }

        public string KhoaYeuCauBaoGia
        {
            get
            {
                return this.mKhoaYeuCauBaoGia;
            }
            set
            {
                this.mKhoaYeuCauBaoGia = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NgayChungTu
        {
            get
            {
                return this.mNgayChungTu;
            }
            set
            {
                this.mNgayChungTu = value;
            }
        }

        public string NgaySua
        {
            get
            {
                return this.mNgaySua;
            }
            set
            {
                this.mNgaySua = value;
            }
        }

        public string NgayTao
        {
            get
            {
                return this.mNgayTao;
            }
            set
            {
                this.mNgayTao = value;
            }
        }

        public string NguoiLienHe
        {
            get
            {
                return this.mNguoiLienHe;
            }
            set
            {
                this.mNguoiLienHe = value;
            }
        }

        public string Reply
        {
            get
            {
                return this.mReply;
            }
            set
            {
                this.mReply = value;
            }
        }

        public string SoChungTu
        {
            get
            {
                return this.mSoChungTu;
            }
            set
            {
                this.mSoChungTu = value;
            }
        }

        public string SoYeuCauBaoGia
        {
            get
            {
                return this.mSoYeuCauBaoGia;
            }
            set
            {
                this.mSoYeuCauBaoGia = value;
            }
        }

        public double TienHang
        {
            get
            {
                return this.mTienHang;
            }
            set
            {
                this.mTienHang = value;
            }
        }

        public double TienHangNT
        {
            get
            {
                return this.mTienHangNT;
            }
            set
            {
                this.mTienHangNT = value;
            }
        }

        public double TienThue
        {
            get
            {
                return this.mTienThue;
            }
            set
            {
                this.mTienThue = value;
            }
        }

        public double TienThueNT
        {
            get
            {
                return this.mTienThueNT;
            }
            set
            {
                this.mTienThueNT = value;
            }
        }

        public int TinhTrang
        {
            get
            {
                return this.mTinhTrang;
            }
            set
            {
                this.mTinhTrang = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

